<template>
  <div class="social-signup-container">
    <div class="sign-btn" @click="wechatHandleClick('wechat')">
      <span class="wx-svg-container"><svg-icon icon-class="wechat" class="icon"/></span>
      微信
    </div>
    <div class="sign-btn" @click="tencentHandleClick('tencent')">
      <span class="qq-svg-container"><svg-icon icon-class="qq" class="icon"/></span>
      QQ
    </div>

    <!---
    <el-dialog
      title="第三方登录窗口"
      :visible.sync="dialogVisible"
      top="50px"
      center="true"
      width="40%"
      height="60%"
    >
      <iframe style="width:560px; height: 480px; margin-top: 10px; margin-top: -10px; scrolling: no" :src="thirdLoginUrl"></iframe>
    </el-dialog>
    -->
  </div>
</template>

<script>
// import openWindow from '@/utils/open-window'
import request from '@/utils/request'


function openWindow(url, name, iWidth, iHeight) {
  //获得窗口的垂直位置
  let iTop = (window.screen.availHeight - 30 - iHeight) / 2;
  //获得窗口的水平位置
  let iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
  window.open(url, name, 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
}

export default {
  name: 'SocialSignin',
  data() {
    return {
      dialogVisible: false,
      thirdLoginUrl: ''
    }
  },
  methods: {
    wechatHandleClick(thirdpart) {
      alert('ok')
      // this.$store.commit('SET_AUTH_TYPE', thirdpart)
      // const appid = 'xxxxx'
      // const redirect_uri = encodeURIComponent('xxx/redirect?redirect=' + window.location.origin + '/auth-redirect')
      // const url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&response_type=code&scope=snsapi_login#wechat_redirect'
      // openWindow(url, thirdpart, 540, 540)
    },
    tencentHandleClick(thirdpart) {
      //alert('ok')
      // this.$store.commit('SET_AUTH_TYPE', thirdpart)
      // const client_id = 'xxxxx'
      // const redirect_uri = encodeURIComponent('xxx/redirect?redirect=' + window.location.origin + '/auth-redirect')
      // const url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri
      // openWindow(url, thirdpart, 540, 540)
      //这里应该去调用第三方登录的接口；简单粗暴直接调用接口。

      //openWindow(url, thirdpart, 540, 540)
      request({
        url: 'http://localhost:8090/web-project/oauth/render',
        method: 'get'
      }).then(resp => {
        console.log(resp);
        openWindow(resp.data, '第三方登录窗口',600,400);
        //this.thirdLoginUrl = resp.data;
        //this.dialogVisible = true; //把模态窗口显示出来...

      })

    }
  }
}
</script>

<style lang="scss" scoped>
.social-signup-container {
  margin: 20px 0;

  .sign-btn {
    display: inline-block;
    cursor: pointer;
  }

  .icon {
    color: #fff;
    font-size: 24px;
    margin-top: 8px;
  }

  .wx-svg-container,
  .qq-svg-container {
    display: inline-block;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    padding-top: 1px;
    border-radius: 4px;
    margin-bottom: 20px;
    margin-right: 5px;
  }

  .wx-svg-container {
    background-color: #24da70;
  }

  .qq-svg-container {
    background-color: #6BA2D6;
    margin-left: 50px;
  }
}
</style>
